package com.quik.web.room.mapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.quik.backend.mapper.BaseDao;
import com.quik.entity.Room;
import com.quik.entity.RoomArea;
import com.quik.entity.RoomType;
import com.quik.entity.RoomTypeBoundProduct;

/**
 * 功能说明:
 *         房间业务逻辑的数据持久化类
 * @author Jenny
 *
 */
@Repository
public class RoomDao extends BaseDao<Room>{
	/**
	 * 根据条件查询房间类型总数
	 * @param roomType
	 * @param productNo
	 * @param productName
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public int findRoomTypeCount(String roomTypeName, String productNo, String productName) throws Exception{
		Map map = new HashMap(3);
		map.put("roomTypeName", roomTypeName == null ? null : roomTypeName.trim());
		map.put("productNo", productNo == null ? null : productNo.trim());
		map.put("productName", productName == null ? null : productName.trim());
		
		int count = (Integer)this.get("findRoomTypeCount", map);
		return count;
	}
	
	/**
	 * 根据条件查询房间类型列表（分页）
	 * @param roomType
	 * @param productNo
	 * @param productName
	 * @param intPage
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	public List findRoomType(String roomTypeName, String productNo, String productName, 
			Integer intPage, Integer pageSize) throws Exception{
		Map map = new HashMap(5);
		map.put("roomTypeName", roomTypeName == null ? null : roomTypeName.trim());
		map.put("productNo", productNo == null ? null : productNo.trim());
		map.put("productName", productName == null ? null : productName.trim());
		map.put("currPage", (intPage - 1) * pageSize);
		map.put("pageSize", pageSize);
		
		List list = this.load("findRoomType", map);
		
		return list;
	}
	

	/**
	 * 根据房间类型查询房间类型总数
	 * @param roomTYpeName
	 * @return
	 * @throws Exception
	 */
	public int findRoomTypeCountByName(String roomTypeName) throws Exception{
		int count = (Integer)this.get("findRoomTypeCountByName", (Object)roomTypeName);
		return count;
	}
	
	/**
	 * 新增房间类型
	 * @param roomType
	 * @throws Exception
	 */
	public void addRoomType(RoomType roomType, RoomTypeBoundProduct boundProduct) throws Exception{
		add("addRoomType", roomType);
		
		if(boundProduct != null){
			RoomType type = (RoomType)get("findRoomTypeByName", (Object)roomType.getRoom_type_name());
			boundProduct.setRoom_type_id(type.getId());
		
			add("addRoomTypeBoundProduct", boundProduct);
		}
	}
	
	/**
	 * 根据条件查询房间区域总数
	 * @param roomAreaName
	 * @return
	 * @throws Exception
	 */
	public int findRoomAreaCount(String roomAreaName) throws Exception{
		int count = (Integer)get("findRoomAreaCount", (Object)roomAreaName);
		return count;
	}
	
	/**
	 * 根据条件查询房间区域列表（分页）
	 * @param roomAreaName
	 * @param intPage
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	public List findRoomArea(String roomAreaName, int intPage, int pageSize) throws Exception{
		Map map = new HashMap(3);
		map.put("roomAreaName", roomAreaName == null?null:roomAreaName.trim());		
		map.put("currPage", (intPage - 1) * pageSize);
		map.put("pageSize", pageSize);
		
		List list = load("findRoomArea", map);
		
		return list;
	}
	
	/**
	 * 根据房间区域名称查询房间区域总数
	 * @param areaName
	 * @return
	 * @throws Exception
	 */
	public int findRoomAreaCountByRoomAreaName(String areaName) throws Exception{
		int count = (Integer)get("findRoomAreaCountByRoomAreaName", (Object)areaName);
		return count;
	}
	
	/**
	 * 新增房间区域
	 * @param area
	 * @throws Exception
	 */
	public void addRoomArea(RoomArea area) throws Exception{
		add("addRoomArea", area);
	}
	
	/**
	 * 根据条件查询房间总数
	 * @param roomNo
	 * @param roomTypeName
	 * @param roomAreaName
	 * @return
	 * @throws Exception
	 */
	public int findRoomCount(String roomNo, String roomTypeName, String roomAreaName) throws Exception{
		Map map = new HashMap(3);
		map.put("roomNo", roomNo == null ? null : roomNo.trim());
		map.put("roomTypeName", roomTypeName == null ? null : roomTypeName.trim());
		map.put("roomAreaName", roomAreaName == null ? null : roomAreaName.trim());
		
		int count = (Integer)get("findRoomCount", map);
		return count;
	}
	
	/**
	 * 根据条件查询房间列表
	 * @param roomNo
	 * @param roomTypeName
	 * @param roomAreaName
	 * @return
	 * @throws Exception
	 */
	public List findRoom(String roomNo, String roomTypeName, String roomAreaName,
			Integer intPage, Integer pageSize) throws Exception{
		Map map = new HashMap(5);
		map.put("roomNo", roomNo == null ? null : roomNo.trim());
		map.put("roomTypeName", roomTypeName == null ? null : roomTypeName.trim());
		map.put("roomAreaName", roomAreaName == null ? null : roomAreaName.trim());
		map.put("currPage", (intPage - 1) * pageSize);
		map.put("pageSize", pageSize);
		
		List roomList = load("findRoom", map);
		return roomList;
	}
	
	/**
	 * 根据房间编号查询房间数量
	 * @return
	 */
	public int findRoomCountByRoomNo(String roomNo) throws Exception{
		int count = (Integer)get("findRoomCountByRoomNo", (Object)roomNo);
		return count;
	}
	
	/**
	 * 新增房间
	 * @param room
	 * @throws Exception
	 */
	public void addRoom(Room room) throws Exception{
		add("addRoom", room);
	}
}
